package com.xframe.xdal.core.model.sqlbuilder;


import com.xframe.xdal.core.constant.DataSourceTypeEnums;
import com.xframe.xdal.core.model.sqlbuilder.factory.*;

/**
 * 功能描述:SqlBuilder构造工厂 基类
 *
 * @author xufeng
 * @version 1.0
 * @date 2022-09-26
 */
public abstract class SqlBuilderFactory {

    public abstract BaseSqlBuilder create(DataSourceTypeEnums dataSourceTypeEnums);

    public static BaseSqlBuilder create(SqlKey key, DataSourceTypeEnums dataSourceTypeEnums){
        SqlBuilderFactory sqlBuilderFactory = null;
        BaseSqlBuilder sqlBuilder = null;
        switch (key){
            case INSERT:
                sqlBuilderFactory = new DefSaveBuilderFactory();
                break;
            case UPDATE_MANY:
                sqlBuilderFactory = new DefUpdateManyBuilderFactory();
                break;
            case UPDATE:
                sqlBuilderFactory = new UpdateSqlBuilderFactory();
                break;
            case PAGESEARCH:
                sqlBuilderFactory = new PageSearchSqlBuilderFactory();
                break;
            case COUNT:
                sqlBuilderFactory = new CountPageSqlBuilderFactory();
                break;
            case SEARCH:
                sqlBuilderFactory = new SearchSqlBuilderFactory();
                break;
            case EXISTS:
                sqlBuilderFactory = new ExistsByKeySqlBuilderFactory();
                break;
            case EXISTS_BY_KEY:
                sqlBuilderFactory = new ExistSqlBuilerFactory();
                break;
            case SEARCH_KEY:
                sqlBuilderFactory = new SearchByKeySqlBuilderFactory();
                break;
            case DELETE:
                sqlBuilderFactory = new DeleteSqlBuilderFactory();
                break;
            case DELETE_MANY:
                sqlBuilderFactory = new DefDeleteManySqlBuilderFactoey();
                break;
            case MANY_INSERT:
                sqlBuilderFactory = new DefManyInsertBuilderFactory();
                break;
            case BATCH_SAVE:
                sqlBuilderFactory = new DefBatchSaveBuilderFactory();
        }
        if(sqlBuilderFactory != null){
            sqlBuilder = sqlBuilderFactory.create(dataSourceTypeEnums);
        }
        return sqlBuilder;
    }


}
